package com.example.requestheaders.config;

import com.example.requestheaders.filter.CustomAuthFilter;
import com.example.requestheaders.interceptor.CustomInterceptor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0.0
 * @description:
 * @author: guorf
 * @time: 2021/12/27 11:38
 */
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        CustomInterceptor customInterceptor= new CustomInterceptor();
        registry.addInterceptor(customInterceptor);
    }

    @Bean
    public FilterRegistrationBean servletRegistrationBean() {
        CustomAuthFilter customAuthFilter = new CustomAuthFilter();
        FilterRegistrationBean<CustomAuthFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(customAuthFilter);
        bean.setName("customAuthFilter");
        bean.addUrlPatterns("/*");
        bean.setOrder(Ordered.LOWEST_PRECEDENCE);

        return bean;
    }
}
